package com.gxsyh.nantie.phone.consumer.configure;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @email yom535@outlook.com
 * @author: 有民(yom535)
 * @date: 2020/2/13
 * @time: 15:31
 */
@Configuration
public class CacheConfiguration {

    @Bean(name = "CacheCon")
    public Cache<String, Object> cacheConig() {
        return CacheBuilder.newBuilder()
                // 设置缓存的最大容量
                .maximumSize(1000000)
                // 设置缓存在写入3秒后失效
                .expireAfterWrite(3, TimeUnit.SECONDS)
                // 设置并发级别为1000
                .concurrencyLevel(1000)
                .build();
    }
}
